<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<LINK REL=STYLESHEET TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
<META NAME="GENERATOR" CONTENT="Java2HTML Version 1.5">
<TITLE>czestmyr.jjsched.ActionExecutor (Java2HTML)</TITLE>
</HEAD>
<BODY><TABLE id="Header" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2" width="33%">&nbsp;</td>
<td align="center" colspan="2" width="33%">
<font size="4">ActionExecutor.java</font>
</td>
<td align="right" colspan="2" width="33%">&nbsp;</td>
</tr>
</TABLE>
<pre ID="Classes">
<A NAME="1"></A><FONT ID="MultiLineComment">/*  This file is a part of JJSched source code
<A NAME="2"></A>    JJSched - Java Jabber Scheduler - a simple Jabber scheduling application
<A NAME="3"></A>    Copyright (C) 2008 Cestmir "CZestmyr" Houska
<A NAME="4"></A>
<A NAME="5"></A>    This program is free software: you can redistribute it and/or modify
<A NAME="6"></A>    it under the terms of the GNU General Public License as published by
<A NAME="7"></A>    the Free Software Foundation, either version 3 of the License, or
<A NAME="8"></A>    (at your option) any later version.
<A NAME="9"></A>
<A NAME="10"></A>    This program is distributed in the hope that it will be useful,
<A NAME="11"></A>    but WITHOUT ANY WARRANTY; without even the implied warranty of
<A NAME="12"></A>    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
<A NAME="13"></A>    GNU General Public License for more details.
<A NAME="14"></A>
<A NAME="15"></A>    You should have received a copy of the GNU General Public License
<A NAME="16"></A>    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt; */</FONT>
<A NAME="17"></A>
<A NAME="18"></A><FONT ID="Package">package</FONT> czestmyr.jjsched;
<A NAME="19"></A>
<A NAME="20"></A><FONT ID="FormalComment">/**
<A NAME="21"></A> * Executes the actions that are parsed by CommandParser.
<A NAME="22"></A> */</FONT>
<A NAME="23"></A><FONT ID="Public">public</FONT> <FONT ID="Class">class</FONT> ActionExecutor {
<A NAME="24"></A>    ActionExecutor(<A HREF="../../czestmyr/jjsched/Connector.java.html">Connector</A> c, <A HREF="../../czestmyr/jjsched/DatabaseConnector.java.html">DatabaseConnector</A> dbc, <A HREF="../../czestmyr/jjsched/Config.java.html">Config</A> conf, <A HREF="../../czestmyr/jjsched/TimeHandler.java.html">TimeHandler</A> t, <A HREF="../../czestmyr/jjsched/jjsched.java.html">jjsched</A> j) {
<A NAME="25"></A>        theConnector = c;
<A NAME="26"></A>        theDBConnector = dbc;
<A NAME="27"></A>        theConfig = conf;
<A NAME="28"></A>        theMaster = j;
<A NAME="29"></A>        theTime = t;
<A NAME="30"></A>    }
<A NAME="31"></A>
<A NAME="32"></A>    <FONT ID="FormalComment">/**
<A NAME="33"></A>     * Executes the given action.
<A NAME="34"></A>     *
<A NAME="35"></A>     * @param action    The action to execute.
<A NAME="36"></A>     */</FONT>
<A NAME="37"></A>    <FONT ID="Public">public</FONT> <FONT ID="Void">void</FONT> execute(<A HREF="../../czestmyr/jjsched/Action.java.html">Action</A> action) {
<A NAME="38"></A>        String message = <FONT ID="Null">null</FONT>;
<A NAME="39"></A>
<A NAME="40"></A>        <FONT ID="SingleLineComment">//DEBUG:
<A NAME="41"></A></FONT>        action.dump();
<A NAME="42"></A>
<A NAME="43"></A>        <FONT ID="Try">try</FONT> {
<A NAME="44"></A>            <FONT ID="Switch">switch</FONT>(action.id){
<A NAME="45"></A>                <FONT ID="Case">case</FONT> NONE:
<A NAME="46"></A>                    <FONT ID="SingleLineComment">//Do nothing
<A NAME="47"></A></FONT>                <FONT ID="Break">break</FONT>;
<A NAME="48"></A>                <FONT ID="Case">case</FONT> ECHO:
<A NAME="49"></A>                    theConnector.sendMessage(action.sParam1, action.user);
<A NAME="50"></A>                <FONT ID="Break">break</FONT>;
<A NAME="51"></A>                <FONT ID="Case">case</FONT> ERROR:
<A NAME="52"></A>                    <FONT ID="If">if</FONT> (theConfig.getInt(<FONT ID="StringLiteral">"ShowErrorMessages"</FONT>) != <FONT ID="Null">null</FONT> &amp;&amp;
<A NAME="53"></A>                        theConfig.getInt(<FONT ID="StringLiteral">"ShowErrorMessages"</FONT>).intValue() == <FONT ID="IntegerLiteral">1</FONT>) {
<A NAME="54"></A>                        theConnector.sendMessage(action.sParam1, action.user);
<A NAME="55"></A>                    }   
<A NAME="56"></A>                <FONT ID="Break">break</FONT>;
<A NAME="57"></A>                <FONT ID="Case">case</FONT> MESSAGE:
<A NAME="58"></A>                    <FONT ID="If">if</FONT> (theConfig.getInt(<FONT ID="StringLiteral">"ShowInfoMessages"</FONT>) != <FONT ID="Null">null</FONT> &amp;&amp;
<A NAME="59"></A>                        theConfig.getInt(<FONT ID="StringLiteral">"ShowInfoMessages"</FONT>).intValue() == <FONT ID="IntegerLiteral">1</FONT>) {
<A NAME="60"></A>                        theConnector.sendMessage(action.sParam1, action.user);
<A NAME="61"></A>                    }   
<A NAME="62"></A>                <FONT ID="Break">break</FONT>;
<A NAME="63"></A>                <FONT ID="Case">case</FONT> REGISTER:  
<A NAME="64"></A>                    theDBConnector.registerUser(action.otherUser);
<A NAME="65"></A>                    message = <FONT ID="StringLiteral">"Registered user "</FONT> + action.otherUser;
<A NAME="66"></A>                    <FONT ID="SingleLineComment">//Inform the other user about registering
<A NAME="67"></A></FONT>                    theConnector.sendMessage(<FONT ID="StringLiteral">"You have been registered to JJSched. To read a short tutorial to help you using\n"</FONT>
<A NAME="68"></A>                                           + <FONT ID="StringLiteral">"JJSched, send message 'help tutorial' to this jabber contact."</FONT>, action.otherUser);
<A NAME="69"></A>                <FONT ID="Break">break</FONT>;
<A NAME="70"></A>                <FONT ID="Case">case</FONT> UNREGISTER:
<A NAME="71"></A>                    theDBConnector.unregisterUser(action.otherUser);
<A NAME="72"></A>                    message = <FONT ID="StringLiteral">"Unregistered user "</FONT> + action.otherUser;
<A NAME="73"></A>                    <FONT ID="SingleLineComment">//Inform the other user about unregistering
<A NAME="74"></A></FONT>                    theConnector.sendMessage(<FONT ID="StringLiteral">"You have been unregistered from JJSched."</FONT>, action.otherUser);
<A NAME="75"></A>                <FONT ID="Break">break</FONT>;
<A NAME="76"></A>                <FONT ID="Case">case</FONT> LIST_USERS:
<A NAME="77"></A>                    message = theDBConnector.getUsers();
<A NAME="78"></A>                <FONT ID="Break">break</FONT>;
<A NAME="79"></A>                <FONT ID="Case">case</FONT> LIST_ADMINS:
<A NAME="80"></A>                    message = theDBConnector.getAdmins();
<A NAME="81"></A>                <FONT ID="Break">break</FONT>;
<A NAME="82"></A>                <FONT ID="Case">case</FONT> LIST_GROUPS:
<A NAME="83"></A>                    message = theDBConnector.getGroups();
<A NAME="84"></A>                <FONT ID="Break">break</FONT>;
<A NAME="85"></A>                <FONT ID="Case">case</FONT> QUIT:
<A NAME="86"></A>                    theMaster.quit();
<A NAME="87"></A>                <FONT ID="Break">break</FONT>;
<A NAME="88"></A>                <FONT ID="Case">case</FONT> PLAN:
<A NAME="89"></A>                    theDBConnector.addEvent(action.plan);
<A NAME="90"></A>                    message = <FONT ID="StringLiteral">"Added a plan for "</FONT>;
<A NAME="91"></A>                    <FONT ID="If">if</FONT> (action.plan.groupId == <FONT ID="IntegerLiteral">0</FONT>) {
<A NAME="92"></A>                        message += action.plan.username;
<A NAME="93"></A>                    } <FONT ID="Else">else</FONT> {
<A NAME="94"></A>                        message += action.plan.groupId;
<A NAME="95"></A>                    }
<A NAME="96"></A>                    message += <FONT ID="StringLiteral">" at "</FONT>
<A NAME="97"></A>                            + theTime.getFormattedTime(theDBConnector.getUserTimeOffset(action.plan.username)+action.plan.timestamp)
<A NAME="98"></A>                            + <FONT ID="StringLiteral">" in user time."</FONT>;
<A NAME="99"></A>                <FONT ID="Break">break</FONT>;
<A NAME="100"></A>                <FONT ID="Case">case</FONT> SETOFFSET:
<A NAME="101"></A>                    theDBConnector.setUserTimeOffset(action.otherUser, action.lParam);
<A NAME="102"></A>                    message = <FONT ID="StringLiteral">"The offset for user "</FONT>+action.otherUser+<FONT ID="StringLiteral">" was set to "</FONT>+theTime.getFormattedOffset(action.lParam);
<A NAME="103"></A>                <FONT ID="Break">break</FONT>;
<A NAME="104"></A>                <FONT ID="Case">case</FONT> GROUP_ADD:
<A NAME="105"></A>                    message = theDBConnector.addGroup(action.sParam1, action.sParam2);
<A NAME="106"></A>                <FONT ID="Break">break</FONT>;
<A NAME="107"></A>                <FONT ID="Case">case</FONT> GROUP_MODIFY:
<A NAME="108"></A>                    message = theDBConnector.modifyGroup(action.lParam, action.sParam1, action.sParam2, action.iParam);
<A NAME="109"></A>                <FONT ID="Break">break</FONT>;
<A NAME="110"></A>                <FONT ID="Case">case</FONT> GROUP_LISTUSERS:
<A NAME="111"></A>                    message = theDBConnector.listGroupUsers(action.lParam);
<A NAME="112"></A>                <FONT ID="Break">break</FONT>;
<A NAME="113"></A>                <FONT ID="Case">case</FONT> GROUP_SUBSCRIBE:
<A NAME="114"></A>                    message = theDBConnector.subscribeToGroup(action.lParam, action.otherUser);
<A NAME="115"></A>                <FONT ID="Break">break</FONT>;
<A NAME="116"></A>                <FONT ID="Case">case</FONT> GROUP_UNSUBSCRIBE:
<A NAME="117"></A>                    message = theDBConnector.unsubscribeFromGroup(action.lParam, action.otherUser);
<A NAME="118"></A>                <FONT ID="Break">break</FONT>;
<A NAME="119"></A>                <FONT ID="Case">case</FONT> GROUP_PRIVILEGES:
<A NAME="120"></A>                    message = theDBConnector.setUserGroupPrivileges(action.lParam, action.otherUser, action.iParam);
<A NAME="121"></A>                <FONT ID="Break">break</FONT>;
<A NAME="122"></A>                <FONT ID="Case">case</FONT> GROUP_ADMIN:
<A NAME="123"></A>                    message = theDBConnector.setAdminPrivileges(action.otherUser, action.iParam);
<A NAME="124"></A>                <FONT ID="Break">break</FONT>;
<A NAME="125"></A>                <FONT ID="Case">case</FONT> GROUP_REMOVE:
<A NAME="126"></A>                    message = theDBConnector.removeGroup(action.lParam);
<A NAME="127"></A>                <FONT ID="Break">break</FONT>;
<A NAME="128"></A>                <FONT ID="Case">case</FONT> GROUP_LISTEVENTS:
<A NAME="129"></A>                    message = theDBConnector.listGroupEvents(action.lParam);
<A NAME="130"></A>                <FONT ID="Break">break</FONT>;
<A NAME="131"></A>                <FONT ID="Case">case</FONT> LIST_EVENTS:
<A NAME="132"></A>                    message = theDBConnector.listUserEvents(action.user);
<A NAME="133"></A>                <FONT ID="Break">break</FONT>;
<A NAME="134"></A>            }
<A NAME="135"></A>        } <FONT ID="Catch">catch</FONT> (Exception e) {
<A NAME="136"></A>            <FONT ID="If">if</FONT> (theConfig.getInt(<FONT ID="StringLiteral">"ShowErrorMessages"</FONT>) != <FONT ID="Null">null</FONT> &amp;&amp;
<A NAME="137"></A>                theConfig.getInt(<FONT ID="StringLiteral">"ShowErrorMessages"</FONT>).intValue() == <FONT ID="IntegerLiteral">1</FONT>)
<A NAME="138"></A>                theConnector.sendMessage(<FONT ID="StringLiteral">"Operation unsuccessful: "</FONT>+e.getMessage(), action.unescapedUser);
<A NAME="139"></A>        }
<A NAME="140"></A>
<A NAME="141"></A>        <FONT ID="SingleLineComment">// If there's a status message to be sent back to the user, send it
<A NAME="142"></A></FONT>        <FONT ID="If">if</FONT> (message != <FONT ID="Null">null</FONT> &amp;&amp;
<A NAME="143"></A>            theConfig.getInt(<FONT ID="StringLiteral">"ShowInfoMessages"</FONT>) != <FONT ID="Null">null</FONT> &amp;&amp;
<A NAME="144"></A>            theConfig.getInt(<FONT ID="StringLiteral">"ShowInfoMessages"</FONT>).intValue() == <FONT ID="IntegerLiteral">1</FONT>){
<A NAME="145"></A>            theConnector.sendMessage(message, action.unescapedUser);
<A NAME="146"></A>        }
<A NAME="147"></A>
<A NAME="148"></A>        <FONT ID="Return">return</FONT>;
<A NAME="149"></A>    }
<A NAME="150"></A>
<A NAME="151"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/Connector.java.html">Connector</A> theConnector;
<A NAME="152"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/Config.java.html">Config</A> theConfig;
<A NAME="153"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/DatabaseConnector.java.html">DatabaseConnector</A> theDBConnector;
<A NAME="154"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/TimeHandler.java.html">TimeHandler</A> theTime;
<A NAME="155"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/jjsched.java.html">jjsched</A> theMaster;
<A NAME="156"></A>}
<A NAME="157"></A>
<A NAME="158"></A></pre>
</BODY>
</HTML>